package com.dkm.orproject.dkmoa.action;

import com.dkm.orproject.dkmoa.dao.OaPersonnelMapper;
import com.dkm.orproject.dkmoa.domain.OaPersonnel;
import com.dkm.orproject.utils.jwt.jwtutils.TokenUtil;
import com.dkm.orproject.utils.utils.FileTools;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @PROJECT_NAME: orproject
 * @DESCRIPTION:
 * @USER: 周佳佳
 * @DATE: 2020/7/23 15:13
 */
@RestController
@Api(tags="地址接口文档")
@RequestMapping("dz")
public class AA {
    @Autowired
    TokenUtil tokenUtil;
    @Resource
    OaPersonnelMapper personnel;
    @Autowired
    FileTools tools;

    @ApiOperation(value = "Post请求 根据微信用户唯一主键查地址 需要传入 exp3:'微信唯一主键'",notes = "返回地址模型的json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "addId",value = "地址主键"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "userId",value = "用户主键"),
            @ApiImplicitParam(paramType = "query",dataType = "String",name = "addName",value = "地址名字"),
            @ApiImplicitParam(paramType = "query",dataType = "String",name = "addressPeople",value = "收货人"),
            @ApiImplicitParam(paramType = "query",dataType = "String",name = "addressPhone",value = "收货电话"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "isva",value = "是否有效 1有效 0无效"),
            @ApiImplicitParam(paramType = "query",dataType = "Date",name = "optime",value = "操作时间"),
            @ApiImplicitParam(paramType = "query",dataType = "String",name = "exp3",value = "微信唯一主键"),
            @ApiImplicitParam(paramType = "query",dataType = "Integer",name = "sort",value = "排序")
    })
    @ApiResponses({
            @ApiResponse(code = 401,message="没有权限"),
            @ApiResponse(code = 403,message = "服务器拒绝请求"),
            @ApiResponse(code = 404,message="请求路径没有或页面跳转路径不对"),
            @ApiResponse(code = 500,message="后台报错"),
            @ApiResponse(code = 200,message="返回成功")
    })

    @GetMapping("dzz")
    public Map<String,Object> dd(){
        Map<String,Object>  map=new HashMap<>();
        OaPersonnel oaPersonnel=new OaPersonnel();
        oaPersonnel.setPkPersonnelId(322223L);
        oaPersonnel.setPersonnelName("周佳佳");
        String jwtToken = tokenUtil.createJwtToken(oaPersonnel);
        map.put("token",jwtToken);
        return map;
    }


    @PostMapping("/saveFile")
    public Map<String, Object> saveFile(@RequestBody MultipartFile file){
        Map<String, Object> map=new ConcurrentHashMap<>();
        try {
            map.put("file",  tools.saveFiletwo("publicFile",file));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    }
}
